Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
kslash is a collection of path utilities.
It is meant to be used as a replacement for node's path
module.
It aims to minimize the problems you get when writing platform independent code dealing with paths.
I hope it might contain some tools of interest to you, even if you target only one platform.
Normalizes the path and converts backslashes to slashes.
slash = require 'kslash'
slash.path 'C:\\Back\\Slash' ▸ C:/Back/Slash
slash.path 'C:\\Back\\Slash\\..\\To\\The\\..\\Future' ▸ C:/Back/To/Future
Windows is capable of handling paths with forward slashes, that's why all exported functions return 'slashed' paths -- except the next one -- which you can use in cases where it isn't :)
Normalizes the path on all platforms.
On Windows it converts
slash.unslash '/c/test' ▸ C:\\test
slash.unslash 'D:/c/test' ▸ D:\\c\\test
p = '/dir/file.txt'
slash.dir(p) ▸ /dir
p = '/dir/file.txt'
slash.file(p) ▸ file.txt
p = '/dir/file.txt'
slash.base(p) ▸ file
p = '/dir/file.txt'
slash.ext(p) ▸ txt
p = '/dir/file.txt'
slash.removeExt(p) ▸ /dir/file
p = '/dir/file.txt'
slash.swapExt(p, 'md') ▸ /dir/file.md
slash.swapExt(p, '.md') ▸ /dir/file.md
slash.isRoot('C:\\') ▸ true
slash.isRoot('/') ▸ true
p = 'C:\\dir\\file.txt'
slash.removeDrive(p) ▸ /dir/file.txt
slash.home() ▸ C:/Users/kodi
p = 'C:/Users/kodi/file.txt'
slash.tilde(p) ▸ ~/file.txt
p = '~/file.txt'
slash.untilde(p) ▸ C:/Users/kodi/file.txt
p = 'C:\\dir/file.txt'
slash.split(p) ▸ ['C:', 'dir', 'file']
p = 'C:\\dir/file.txt'
slash.splitExt(p) ▸ ['C:/dir/file', 'txt']
p = 'C:\\dir/file.txt'
slash.splitDrive(p) ▸ ['/dir/file.txt', 'c']
p = '/dir/file.txt:12:3'
slash.splitFileLine(p) ▸ ['/dir/file.txt', 12, 3]
p = '/dir/file.txt:12'
slash.splitFilePos(p) ▸ ['/dir/file.txt', [0,11]]
p = '/dir/file.txt:12:3'
slash.removeLinePos(p) ▸ /dir/file.txt
p = '/dir/file.txt:12:3'
slash.removeColumn(p) ▸ /dir/file.txt:12
p = '/dir/file.txt:12'
slash.joinFilePos(p, [2, 1]) ▸ /dir/file.txt:2:2
p = '/dir/file.txt'
slash.joinFileLine(p, 1, 2) ▸ /dir/file.txt:1:2
p = '/dir/file.txt'
slash.pathlist(p) ▸ ['/', '/dir', '/dir/file.txt']
Applies unenv
and untilde
before converting path into an absolute one.
Replaces $...
with matching environment variables
p = '$HOME/dir'
slash.unenv(p) ▸ C:/Users/kodi/dir
p = 'C:/test/some/path.txt'
to ='C:/test/some/other/path'
slash.relative(p,to) ▸ ../../path.txt
Resolves
p and q and compares the results.
Encodes p for use as an URL.
p = '/dir/a # b'
slash.encode(p) ▸ /dir/a%20%23%20b
Encodes p and prefixes it with 'file://'
p = '/dir/a # b'
slash.fileUrl(p) ▸ file:///dir/a%20%23%20b
Returns a joined path of os.tmpdir and an uuid
Searches backwards in pathlist
of p for a package.json and returns the containing folder, if one is found.
Same as pkg
, just looking for .git
directory instead.
Like the unix command, creates intermediate directories if they don't exist.
Calls back with a list of info objects for items in directory p.
A small wrapper around the walkdir
package.
Returns stat of path p if it exists, null otherwise.
The callback is optional. If provided, the test is executed asynchronously and the callback will be called with the result
slash.exists p, (stat) -> if stat then # ...
The same is true for the following functions that have a callback argument:
Returns stat of path p if it is a directory, null otherwise.
Returns stat of path p if it is a file, null otherwise.
Returns true if p is writable.
Returns true if p is a textfile.
Returns content of p as an utf8 string. Returns an empty string, if p doesn't exist or isn't readable.
Returns p if p doesn't exist. Otherwise, returns a path with a number attached such that the path doesn't exist.
Removes leading and trailing newlines from path p.
Returns true if path.sep is '\'.
Same as the functions of the path
module but p is sanitized
and slashed
first.
All functions return an empty string or null if the provided path is an empty string, null or undefined. The same is true, if an underlying function call throws an error.
If this is too lax for your taste, or you want to debug your code, you can redefine the function slash.error
:
slash.error = (msg) -> # throw or log or something else ...
FAQs
path tool
The npm package kslash receives a total of 61 weekly downloads. As such, kslash popularity was classified as not popular.
We found that kslash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.